package main

import (
	"sync"
	"time"
)

// 互斥锁
var x = 0

func Add() {
	defer gw.Done()
	huchisuo.Lock()
	x++
	println(x)

	time.Sleep(time.Millisecond * 100)
	huchisuo.Unlock()
}

var gw sync.WaitGroup
var huchisuo sync.Mutex // 互斥锁

func main() {
	gw.Add(100)
	for i := 0; i < 100; i++ {
		go Add()
	}
	gw.Wait()
}
